<?php
// 本文档自动生成，仅供测试运行
class ContentAction extends Action
{

	/**
	 * ------------------------------
	 * 预处理
	 * ------------------------------
	 */
	function _initialize(){
		if( !isset($_SESSION['adm_name']) or !isset($_SESSION['isAdmin']) ) $this->redirect('Index/login');
	}

	 
    /**
	 * ------------------------------
	 * 搜索微博
	 * ------------------------------
	 */
	function search(){
		 $name=$_REQUEST['name'];
		 $this->assign('name',$name);	 	
		import("@.ORG.Page");
		$count	= M('weibo')->where("content like '%$name%'")->count();
		$Page	= New Page($count,15);
		$show	= $Page->show();
		$list = M('weibo')->where("content like '%$name%'")->order('time desc,id desc')->limit($Page->firstRow.','.$Page->listRows)
						     ->select();

		
	    $this->assign('list', $list);
		$this->assign('page', $show);
		$this->assign('pagetitle', '搜索微博列表');
	
		$this->display('weibo');
	 }	

 
	/**
	 * ------------------------------
	 * 频道管理
	 * ------------------------------
	 */
	function pindao(){
	
		import("@.ORG.Page");
		$count	= M('pindao')->count();
		$Page	= New Page($count,15);
		$show	= $Page->show();
		$list = M('pindao')->order('xu asc,id asc')->limit($Page->firstRow.','.$Page->listRows)
						     ->select();
	    $this->assign('list', $list);
		$this->assign('page', $show);
		$this->assign('pagetitle', '频道名列表');
	
		$this->display();
	 }
	
	function editpindao(){
        $id = intval($_GET['id']);
		if($id==''){
		     $this->assign('pagetitle', '添加频道名');
		}else{
			 $list = M('pindao')->find($id);
			 $this->assign($list);
			 $this->assign('type', 'edit');
			 $this->assign('pagetitle', '修改频道名');
		}
		$this->display('pindao_edit');
	}
   
   function dopindao(){
	   
   	    header("Content-Type:text/html; charset=utf-8");
		if( !M()->autoCheckToken($_POST) ) $this->error('禁止站外提交！');
		unset($_POST['__hash__']);
		foreach ($_POST as $k => $v) {
			if($v == '') unset($_POST[$k]);
		}
		
		
		if($_POST['id']){
				if( M('pindao')->save($_POST) ){
					$this->assign('jumpUrl', U('Content/pindao'));
					$this->success('修改成功！');
				}else{
					$this->error('没有任何改动　或　修改失败！');
				}
		}else{
		      if( M('pindao')->add($_POST) ){
					$this->assign('jumpUrl', U('Content/pindao'));
					$this->success('添加成功！');
			  }else{
					$this->error('添加失败！');
			  }
		}
	}
	
	function delpindao(){
	    $ids = $_POST['ids'];
		$del = M('pindao')->where("id IN ($ids)")->delete();
        echo $del?'1':'0';
	}	 

	/**
	 * ------------------------------
	 * 微博管理
	 * ------------------------------
	 */
	function weibo(){
	
		import("@.ORG.Page");
		$count	= M('weibo')->count();
		$Page	= New Page($count,15);
		$show	= $Page->show();
		$list = M('weibo')->order('time desc,id asc')->limit($Page->firstRow.','.$Page->listRows)
						     ->select();

	    $this->assign('list', $list);
		$this->assign('page', $show);
		$this->assign('pagetitle', '微博列表');
	
		$this->display();
	 }
	
	function editweibo(){
        $id = intval($_GET['id']);
		$list1 = M('pindao')->select();
	    $this->assign('list1', $list1);
		if($id==''){
		     $this->assign('pagetitle', '添加微博');
		}else{
			 $list = M('weibo')->find($id);
				foreach($list as $k=>$v){
				 if(get_magic_quotes_gpc()!='-1' || get_magic_quotes_gpc()==true){
					$list[$k]=stripslashes($v); 
				 } 
				}
			 $this->assign($list);
			 $this->assign('type', 'edit');
			 $this->assign('pagetitle', '修改微博');
		}
		$this->display('weibo_edit');
	}
   
   function doweibo(){
	   
   	    header("Content-Type:text/html; charset=utf-8");
		if( !M()->autoCheckToken($_POST) ) $this->error('禁止站外提交！');
		unset($_POST['__hash__']);
		foreach ($_POST as $k => $v) {
			if($v == '') unset($_POST[$k]);
		}
		
		
		if($_POST['id']){
			
				if(!$_POST['tuijian']){
					$_POST['tuijian']="0";
					$_POST['ttime']="0";	
				}else{
					$_POST['ttime']=time();
				}
				if(!$_POST['jiajing']){
					$_POST['jiajing']="0";
					$_POST['jtime']="0";	
				}else{
					$_POST['jtime']=time();
				}
				if(!$_POST['wenzilian']){
					$_POST['wenzilian']="0";
					$_POST['wtime']="0";	
				}else{
					$_POST['wtime']=time();
				}

				
				if( M('weibo')->save($_POST) ){
					$this->assign('jumpUrl', U('Content/weibo'));
					$this->success('修改成功！');
				}else{
					$this->error('没有任何改动　或　修改失败！');
				}
		}else{
		      if( M('weibo')->add($_POST) ){
					$this->assign('jumpUrl', U('Content/weibo'));
					$this->success('添加成功！');
			  }else{
					$this->error('添加失败！');
			  }
		}
	}
	
	function delweibo(){
	    $ids = $_POST['ids'];
		$del = M('weibo')->where("id IN ($ids)")->delete();
        echo $del?'1':'0';
	}	
  

	/**
	 * ------------------------------
	 * 称号管理
	 * ------------------------------
	 */
	function chenghao(){
	
		import("@.ORG.Page");
		$count	= M('chenghao')->count();
		$Page	= New Page($count,15);
		$show	= $Page->show();
		$list = M('chenghao')->order('id desc')->limit($Page->firstRow.','.$Page->listRows)
						     ->select();
	    $this->assign('list', $list);
		$this->assign('page', $show);
		$this->assign('pagetitle', '称号列表');
	
		$this->display();
	 }
	
	function editchenghao(){
        $id = intval($_GET['id']);
		if($id==''){
		     $this->assign('pagetitle', '添加称号');
		}else{
			 $list = M('chenghao')->find($id);
			 $this->assign($list);
			 $this->assign('type', 'edit');
			 $this->assign('pagetitle', '修改称号');
		}
		$this->display('chenghao_edit');
	}
   
   function dochenghao(){
	   
   	    header("Content-Type:text/html; charset=utf-8");
		if( !M()->autoCheckToken($_POST) ) $this->error('禁止站外提交！');
		unset($_POST['__hash__']);
		foreach ($_POST as $k => $v) {
			if($v == '') unset($_POST[$k]);
		}
		
		
		if($_POST['id']){
				if( M('chenghao')->save($_POST) ){
					$this->assign('jumpUrl', U('Content/chenghao'));
					$this->success('修改成功！');
				}else{
					$this->error('没有任何改动　或　修改失败！');
				}
		}else{
		      if( M('chenghao')->add($_POST) ){
					$this->assign('jumpUrl', U('Content/chenghao'));
					$this->success('添加成功！');
			  }else{
					$this->error('添加失败！');
			  }
		}
	}
	
	function delchenghao(){
	    $ids = $_POST['ids'];
		$del = M('chenghao')->where("id IN ($ids)")->delete();
        echo $del?'1':'0';
	}	 

	/**
	 * ------------------------------
	 * 达人管理
	 * ------------------------------
	 */
	function daren(){
	
		import("@.ORG.Page");
		$count	= M('daren')->count();
		$Page	= New Page($count,15);
		$show	= $Page->show();
		$list = M('daren')->order('id desc')->limit($Page->firstRow.','.$Page->listRows)
						     ->select();
	    $this->assign('list', $list);
		$this->assign('page', $show);
		$this->assign('pagetitle', '达人列表');
	
		$this->display();
	 }
	
	function editdaren(){
        $id = intval($_GET['id']);
		if($id==''){
		     $this->assign('pagetitle', '添加达人');
		}else{
			 $list = M('daren')->find($id);
			 $this->assign($list);
			 $this->assign('type', 'edit');
			 $this->assign('pagetitle', '修改达人');
		}
		$this->display('daren_edit');
	}
   
   function dodaren(){
	   
   	    header("Content-Type:text/html; charset=utf-8");
		if( !M()->autoCheckToken($_POST) ) $this->error('禁止站外提交！');
		unset($_POST['__hash__']);
		foreach ($_POST as $k => $v) {
			if($v == '') unset($_POST[$k]);
		}
		
		
		if($_POST['id']){
				if( M('daren')->save($_POST) ){
					$this->assign('jumpUrl', U('Content/daren'));
					$this->success('修改成功！');
				}else{
					$this->error('没有任何改动　或　修改失败！');
				}
		}else{
		      if( M('daren')->add($_POST) ){
					$this->assign('jumpUrl', U('Content/daren'));
					$this->success('添加成功！');
			  }else{
					$this->error('添加失败！');
			  }
		}
	}
	
	function deldaren(){
	    $ids = $_POST['ids'];
		$del = M('daren')->where("id IN ($ids)")->delete();
        echo $del?'1':'0';
	}

	/**
	 * ------------------------------
	 * 皮肤管理
	 * ------------------------------
	 */
	function pifu(){
	
		import("@.ORG.Page");
		$count	= M('pifu')->count();
		$Page	= New Page($count,15);
		$show	= $Page->show();
		$list = M('pifu')->order('id desc')->limit($Page->firstRow.','.$Page->listRows)
						     ->select();
	    $this->assign('list', $list);
		$this->assign('page', $show);
		$this->assign('pagetitle', '皮肤列表');
	
		$this->display();
	 }
	
	function editpifu(){
        $id = intval($_GET['id']);
		if($id==''){
		     $this->assign('pagetitle', '添加皮肤');
		}else{
			 $list = M('pifu')->find($id);
			 $this->assign($list);
			 $this->assign('type', 'edit');
			 $this->assign('pagetitle', '修改皮肤');
		}
		$this->display('pifu_edit');
	}
   
   function dopifu(){
	   
   	    header("Content-Type:text/html; charset=utf-8");
		if( !M()->autoCheckToken($_POST) ) $this->error('禁止站外提交！');
		unset($_POST['__hash__']);
		foreach ($_POST as $k => $v) {
			if($v == '') unset($_POST[$k]);
		}
		
		
		if($_POST['id']){
				if( M('pifu')->save($_POST) ){
					$this->assign('jumpUrl', U('Content/pifu'));
					$this->success('修改成功！');
				}else{
					$this->error('没有任何改动　或　修改失败！');
				}
		}else{
		      if( M('pifu')->add($_POST) ){
					$this->assign('jumpUrl', U('Content/pifu'));
					$this->success('添加成功！');
			  }else{
					$this->error('添加失败！');
			  }
		}
	}
	
	function delpifu(){
	    $ids = $_POST['ids'];
		$del = M('pifu')->where("id IN ($ids)")->delete();
        echo $del?'1':'0';
	}

	/**
	 * ------------------------------
	 * 评论管理
	 * ------------------------------
	 */
	function pinglun(){
	
		import("@.ORG.Page");
		$count	= M('pinglun')->count();
		$Page	= New Page($count,15);
		$show	= $Page->show();
		$list = M('pinglun')->order('id desc')->limit($Page->firstRow.','.$Page->listRows)
						     ->select();
	    $this->assign('list', $list);
		$this->assign('page', $show);
		$this->assign('pagetitle', '皮肤列表');
	
		$this->display();
	 }
	
	function editpinglun(){
        $id = intval($_GET['id']);
		if($id==''){
		     $this->assign('pagetitle', '添加皮肤');
		}else{
			 $list = M('pinglun')->find($id);
			 $this->assign($list);
			 $this->assign('type', 'edit');
			 $this->assign('pagetitle', '修改皮肤');
		}
		$this->display('pinglun_edit');
	}
   
   function dopinglun(){
	   
   	    header("Content-Type:text/html; charset=utf-8");
		if( !M()->autoCheckToken($_POST) ) $this->error('禁止站外提交！');
		unset($_POST['__hash__']);
		foreach ($_POST as $k => $v) {
			if($v == '') unset($_POST[$k]);
		}
		

		if($_POST['id']){
				if( M('pinglun')->save($_POST) ){
					$this->assign('jumpUrl', U('Content/pinglun'));
					$this->success('修改成功！');
				}else{
					$this->error('没有任何改动　或　修改失败！');
				}
		}else{
		      if( M('pinglun')->add($_POST) ){
					$this->assign('jumpUrl', U('Content/pinglun'));
					$this->success('添加成功！');
			  }else{
					$this->error('添加失败！');
			  }
		}
	}
	
	function delpinglun(){
	    $ids = $_POST['ids'];
		$del = M('pinglun')->where("id IN ($ids)")->delete();
        echo $del?'1':'0';
	}

	/**
	 * ------------------------------
	 * 用户管理
	 * ------------------------------
	 */
	function user(){
	
		import("@.ORG.Page");
		$count	= M('user')->count();
		$Page	= New Page($count,15);
		$show	= $Page->show();
		$list = M('user')->order('ctime desc,id desc')->limit($Page->firstRow.','.$Page->listRows)
						     ->select();

	    $this->assign('list', $list);
		$this->assign('page', $show);
		$this->assign('pagetitle', '用户信息列表');
	
		$this->display();
	 }
	
	function edituser(){
        $id = intval($_GET['id']);
		$list1 = M('daren')->select();
	    $this->assign('list1', $list1);
		
		
		if($id==''){
		     $this->assign('pagetitle', '添加用户信息');
		}else{
			 $list = M('user')->find($id);
              if($list['xingbie']==0){
				  $list['xingbie']="男";  
			  }else{
				  $list['xingbie']="女"; 
			  }
			 $this->assign($list);
			 $this->assign('type', 'edit');
			 $this->assign('pagetitle', '修改用户信息');
		}
		$this->display('user_edit');
	}
   
   function douser(){
	   
   	    header("Content-Type:text/html; charset=utf-8");
		if( !M()->autoCheckToken($_POST) ) $this->error('禁止站外提交！');
		unset($_POST['__hash__']);
		foreach ($_POST as $k => $v) {
			if($v == '') unset($_POST[$k]);
		}
		
		
		if($_POST['id']){
			
				if(!$_POST['getuijian']){
					$_POST['getuijian']="0";
					$_POST['gtime']="0";	
				}else{
					$_POST['gtime']=time();	
				}
				if(!$_POST['shoutuijian']){
					$_POST['shoutuijian']="0";	
					$_POST['stime']="0";
				}else{
					$_POST['stime']=time();	
				}

				
				if( M('user')->save($_POST) ){
					$this->assign('jumpUrl', U('Content/user'));
					$this->success('修改成功！');
				}else{
					$this->error('没有任何改动　或　修改失败！');
				}
		}else{
		      if( M('user')->add($_POST) ){
					$this->assign('jumpUrl', U('Content/user'));
					$this->success('添加成功！');
			  }else{
					$this->error('添加失败！');
			  }
		}
	}
	
	function deluser(){
	    $ids = $_POST['ids'];
		$del = M('user')->where("id IN ($ids)")->delete();
        echo $del?'1':'0';
	}	
    /**
	 * ------------------------------
	 * 搜索用户昵称
	 * ------------------------------
	 */
	function searchuser(){
		 $name=$_REQUEST['name'];
		 $this->assign('name',$name);	 	
		import("@.ORG.Page");
		$count	= M('user')->where("nicheng like '%$name%'")->count();
		$Page	= New Page($count,15);
		$show	= $Page->show();
		$list = M('user')->where("nicheng like '%$name%'")->order('ctime desc,id desc')->limit($Page->firstRow.','.$Page->listRows)
						     ->select();

		
	    $this->assign('list', $list);
		$this->assign('page', $show);
		$this->assign('pagetitle', '搜索用户信息列表');
	
		$this->display('user');
	 }	  


 
	
}
?>